package com.zx.service;

import com.zx.base.mybatis.ServiceImpl;
import com.zx.mapper.RightMapper;
import com.zx.pojo.Right;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * 权限业务逻辑实现
 *
 */
@Service
public class RightServiceImpl extends ServiceImpl<RightMapper, Right> implements RightService {

    @Resource
    private RightMapper rightMapper;

    /**
     * 获得所有权限集合
     *
     * @return
     */
    @Override
    @Cacheable(value = "allRight", key = "'all'", unless = "#result==null")
    public List<Right> getAllRight() {
        return rightMapper.selectList(null);
    }

    /**
     * 根据角色ID查找权限集合
     *
     * @param roleId 角色ID
     * @return
     */
    @Override
    @Cacheable(value = "roleRight", key = "'roleId-' + #roleId", unless = "#result==null")
    public Set<Right> findRightByRoleId(Long roleId) {
        return rightMapper.findRightByRoleId(roleId);
    }

}
